﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
using System.Data.SqlClient;
using DataAccessLogic;
using System.Collections;
using System.Data;
using System.Web.Security;

namespace BusinessLogic
{
    [Serializable]
    public abstract class Table
    {
        #region Fields
        protected Guid _id;
        protected DateTime _dateAdded;
        protected DateTime _dateChanged;
        protected Guid _addedByID;
        protected Guid _changedByID;
        protected string _addedBy;
        protected string _changedBy;
        #endregion        
        
        #region Methods
        [Obsolete("This method has been deprecated because of it's performance. Please fill the addedby and changedby fields through your SQL query. For reference look at USP_STATEFORMATTEDTYPECODE_GETALL", false)]
        public void FillAddedByAndChangedBy()
        {
            if(_addedByID != Guid.Empty)
            {
                _addedBy = AppUserDataAccess.GetNameByID(_addedByID);
            }

            if(_changedByID != Guid.Empty)
            {
                _changedBy = AppUserDataAccess.GetNameByID(_changedByID);
            }
        }
        #endregion

        #region Properties
        public Guid ID
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }

        public DateTime DateChanged
        {
            get
            {
                return _dateChanged;
            }
            set
            {
                _dateChanged = value;
            }
        }

        public DateTime DateAdded
        {
            get
            {
                return _dateAdded;
            }
            set
            {
                _dateAdded = value;
            }
        }

        public Guid AddedByID
        {
            get
            {
                return _addedByID;
            }
            set
            {
                _addedByID = value;                
            }
        }

        public Guid ChangedByID
        {
            get
            {
                return _changedByID;
            }
            set
            {
                _changedByID = value;                
            }
        }

        public string AddedBy
        {
            get
            {
                return _addedBy;
            }
            set
            {
                _addedBy = value;
            }
        }

        public string ChangedBy
        {
            get
            {
                return _changedBy;
            }
            set
            {
                _changedBy = value;
            }
        }   
        #endregion
    }
}